import { removeRule, rule } from '@/services/ant-design-pro/api';
import type { ActionType, ProColumns, ProDescriptionsItemProps } from '@ant-design/pro-components';
import {
  FooterToolbar,
  PageContainer,
  ProDescriptions,
  ProTable,
} from '@ant-design/pro-components';
import { FormattedMessage, useIntl, useRequest } from '@umijs/max';
import { Button, Drawer, Input, Modal, message } from 'antd';
import React, { useCallback, useRef, useState } from 'react';
import { Http } from '@/@nasty/Axios';
import { util } from '@/@nasty/Util';
import { AddModel } from './index.model';
import { getRoleTypeText, isNormalRole } from './common';
import { FlowModel } from '@/@nasty/components/Flow';

async function getPageApi(
  params: any,
  options?: any,
) {
  return new Promise<any>((resolve, reject) => {
    Http.post("/Flow/Flow/GetFlowPage", { ...params }, { isLower: true })
      .then((data) => {
        resolve(data);
      }).catch((e) => {
        reject(e)
      })
  });

}


const TableList: React.FC = () => {
  const actionRef = useRef<ActionType>();
  const flowRef = useRef<any>(null);
  /**
   * @en-US International configuration
   * @zh-CN 国际化配置
   * */
  const intl = useIntl();

  const reload = () => {
    actionRef.current?.reloadAndRest?.();
  }

  const openFlow = (data: any) => {
    
    let ps = {
      Id: data.Id,
      Name: data.Name,
      //FlowConfigCode: data.FlowConfigCode,
      //Url: "/Flow/FlowTest/GetFlowTest"
    }

    flowRef.current.open(ps);
  }

  const columns: ProColumns<any>[] = [
    {
      title: "主键",
      dataIndex: 'Id',
      hideInSearch: true,
    },
    {
      title: "名称",
      dataIndex: 'Name'
    },
    {
      title: "流程触发器",
      dataIndex: 'FlowAction',
      hideInSearch: true,
    },
    {
      title: "通知触发器",
      dataIndex: 'NoticeAction',
      hideInSearch: true,
    },
    {
      title: "当前节点",
      dataIndex: 'CurrentNodeCode',
      hideInSearch: true,
    },
    {
      title: "是否结束",
      dataIndex: 'IsEnd',
      hideInSearch: true,
      render: (_, record) => {
        return record.IsEnd ? "是" : "否";
      }
    },
    {
      title: "创建时间",
      dataIndex: 'CreateTime',
      hideInSearch: true,
    },
    {
      title: "创建人",
      dataIndex: 'CreateUser',
      hideInSearch: true,
    },
    {
      title: "操作",
      dataIndex: 'option',
      valueType: 'option',
      render: (_, record) => {
        let actions = [];

        actions.push(   <a onClick={() => {openFlow(record); }}>{"流程"}</a>)

        return actions;
      },
    },
  ];



  return (
    <PageContainer>
      <ProTable<any, any>
        headerTitle={"流程"}
        actionRef={actionRef}
        rowKey="Id"
        search={{
          labelWidth: 120,
        }}
        toolBarRender={() => []}
        request={getPageApi}
        columns={columns}
      />
      <FlowModel ref={flowRef} disabled={true}/>
    </PageContainer>
  );
};

export default TableList;
